package com.itheima.stock.controller;

import com.itheima.stock.pojo.domain.SysPermissionDomain;
import com.itheima.stock.pojo.entity.SysPermission;
import com.itheima.stock.service.PermissionService;
import com.itheima.stock.vo.req.PermissionAddVo;
import com.itheima.stock.vo.req.PermissionUpdateVo;
import com.itheima.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权限的控制器
 */
@RestController
@RequestMapping("/api")
public class PermsController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 查询所有权限集合
     *
     * @return
     */
    @GetMapping("/permissions")
    public R<List<SysPermission>> getAllPerms() {
        return permissionService.getAllPerms();
    }

    /**
     * 添加权限时回显权限树,仅仅显示目录和菜单
     */
    @GetMapping("/permissions/tree")
    public R<List<SysPermissionDomain>> getPermsTree() {
        return permissionService.getPermsTree();
    }

    /**
     * 权限添加按钮
     *
     * @param addVo
     * @return
     */
    @PostMapping("/permission")
    public R addPerms(@RequestBody PermissionAddVo addVo) {
        return permissionService.addPerms(addVo);
    }

    /**
     * 更新权限
     *
     * @param updateVo
     * @return
     */
    @PutMapping("/permission")
    public R updatePerms(@RequestBody PermissionUpdateVo updateVo) {
        return permissionService.updatePerms(updateVo);
    }

    /**
     * 删除权限
     *
     * @param permissionId
     */
    @DeleteMapping("/permission/{permissionId}")
    public R deletePerms(@PathVariable Long permissionId) {
        return permissionService.deletePerms(permissionId);
    }
}